jQuery(document).ready(function(){
	setTimeout(function(){
        $('.progress .progress-bar').each(function() {
            var me = $(this);
            var perc = me.attr("aria-valuemax");
            var current_perc = 0;
            var progress = setInterval(function() {
                if (current_perc>=perc) {
                    clearInterval(progress);
                } else {
                    current_perc += Math.floor((Math.random()*5)+1);
                    if(current_perc > 100)
                    	current_perc = 100;
                    me.css('width', (current_perc)+'%');
                }
                me.text((current_perc)+'%');
            }, 50);
        });
    },290);

	
    jQuery.post('utilResultadosPilotos', function(responseJson) {   
    	if(responseJson && responseJson!=''){
    		jQuery("#pilotoLoading").remove();
    		 var table='<table class="table table-striped">';
    		 table+='<thead><tr><th>Position</th><th>Driver</th><th>Nationality</th><th>Team</th><th>Points</th></tr></thead><tbody>';
    	      $.each( responseJson, function( index, item){
   	            /* add to html string started above*/
    		 	table+='<tr><td>'+item.posicion+'</td><td>'+item.nombre+'</td><td>'+item.nacionalidad+'</td><td><img width="50px" src="assets/img/Teams/'+item.equipo.toLowerCase()+'.png" alt="'+item.equipo+'" />&nbsp;&nbsp;'+item.equipoString+'</td><td>'+item.puntaje+'</td></tr>';       
    	      });
    	      table+='</tbody></table>';
    		/* insert the html string*/
   	      $("#divDriverChampionship").html( table );
    	}else{
    		jQuery("#pilotoLoading").remove();
    		var error = "<h2>An error has ocurred while loading Driver Championship</h2>";
    		$("#divDriverChampionship").html( error );
    	}
    }).fail(function() {
    	jQuery("#pilotoLoading").remove();
		var error = "<h2>An error has ocurred while loading Driver Championship</h2>";
		$("#divDriverChampionship").html( error );
	  });
    
    jQuery.post('utilResultadosEquipos', function(responseJson) {   
    	if(responseJson && responseJson!=''){
    		jQuery("#teamLoading").remove();
    		 var table='<table class="table table-striped">';
    		 table+='<thead><tr><th>Position</th><th>Team</th><th>Points</th></tr></thead><tbody>';
    	      $.each( responseJson, function( index, item){
    		 	table+='<tr><td>'+item.posicion+'</td><td><img height="70px" src="assets/img/Teams/'+item.equipo.toLowerCase()+'.png" alt="'+item.equipo+'" /></td><td>'+item.puntaje+'</td></tr>';       
    	      });
    	      table+='</tbody></table>';
   	      $("#divTeamChampionship").html( table );
    	}else{
    		jQuery("#teamLoading").remove();
    		var error = "<h2>An error has ocurred while loading Team Championship</h2>";
    		$("#divTeamChampionship").html( error );
    	}
    }).fail(function() {
    	jQuery("#teamLoading").remove();
		var error = "<h2>An error has ocurred while loading Team Championship</h2>";
		$("#divTeamChampionship").html( error );
	  });
});